﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Xml;

using System.IO;

namespace Prodcrast
{
    public static class PathEx
    {
        /// <summary>
        /// 
        /// </summary>
        /// <param name="filename"></param>
        /// <returns></returns>
        public static string Sanitize(string filename)
        {
            foreach (char c in Path.GetInvalidPathChars())
            {
                filename = filename.Replace(c, ' ');
            }
            filename = filename.Replace(':', '-');
            filename = filename.Replace('?', ' ');

            filename = new System.Text.RegularExpressions.Regex(@"\s+").Replace(filename, " ");

            return filename;
        }
    }

    public static class XmlNodeExtender
    {
        public static string GetAttributeValue(this XmlNode node, string name)
        {
            return node.GetAttributeValue(name, "");
        }

        public static string GetAttributeValue(this XmlNode node, string name, string defaultValue)
        {
            XmlAttribute attr = node.Attributes[name];

            if (attr != null)
                return attr.Value;
            else
                return defaultValue;
        }
    }
}
